/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { uploadType } from '@/utils/util'
import apiMod from '@/apiMod/index'

let emergencyDegreeList = [
	{
		label: '普通',
		value: '0',
		type: 'info',
		remarks: 'info',
	},
	{
		label: '加急',
		value: '1',
		type: 'danger',
		remarks: 'danger',
	},
]
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '总任务编号', prop: 'taskId' },
		{ label: '总任务名称', prop: 'taskName' },
		// { label: '发起人', prop: 'administrationPidName' },
		{ label: '发起人', prop: 'createUserName' },
		{ label: '接收人', prop: 'administrationName' },
		{ label: '子任务编号', prop: 'taskItemId' },
		{
			label: '总任务优先级',
			prop: 'emergencyDegree',
			custome: 'tag',
			dicData: emergencyDegreeList,
		},
		{ label: '截止时间', prop: 'endTime' },
		{ label: '提交时间', prop: 'fillingTime' },
		{
			label: '任务状态',
			prop: 'taskStatus',
			propName:'taskStatusLabel',
			custome: 'tag',
			code: 'GOVERNMENT_SUB_STATUS',
			api: 'getDictItemList',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_zwglSubTaskInfo_subPage',
}
export const formateBuilData = (form) => {
	let query = {
		...form,
		buildInfo: undefined,
	}
	if (form.buildInfo && form.buildInfoText) {
		query.checkinBuilding = form.buildInfo[0]
		query.checkinFloor = form.buildInfo[1]
		query.checkinRoom = form.buildInfo[2]
		query.checkinBed = form.buildInfo[3]
	}
	return query
}

export const baseConfig = {
	pageName: '待处理的任务',
	// 数据字典
	dictcodes: ['GOVERNMENT_SUB_STATUS'],
	rowKey: 'id',
	tipLabel: 'oldmanName',
	addLabel: '创建',
	api: {
		...api,
	},
	auth: {
		...api,
	},
	paramsObj: {
		viewTaskType: 'RELEASE_SUB_TASK',
	},
	menuAction: [
		{
			label: '预约入住',
			type: 'primary',
			operate: 'appoint',
			auth: 'view_dpElderlyCheckinRecord_page',
			show: false,
		},
	],
	// 当前行操作按钮
	menuBtn: [
		{
			label: '查看详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
		{
			label: '审批',
			type: 'success',
			operate: 'approval',
			condition: `(row) => { return row.taskStatus === 'PENDING_APPROVAL' }`,
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '80%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '总任务编号', prop: 'taskId', type: 'input', span: 6 },
			{ label: '总任务名称', prop: 'taskName', type: 'input', span: 6 },
			{ label: '提交时间', prop: 'fillingTimeBetween', type: 'daterange', format: 'YYYY-MM-DD', valueFormat: 'YYYY年MM月DD日', span: 12 },
			{ label: '子任务编号', prop: 'taskItemId', type: 'input', span: 6 },
			{ label: '发起人', prop: 'administrationPidName', type: 'input', span: 6 },
			{ label: '接收人', prop: 'administrationName', type: 'input', span: 6 },
			{
				label: '任务优先级',
				prop: 'emergencyDegree',
				type: 'select',
				dicData: emergencyDegreeList,
				span: 6,
			},
			{
				label: '任务状态',
				prop: 'taskStatus',
				type: 'remoteSelect',
				code: 'GOVERNMENT_SUB_STATUS',
				api: 'getDictItemList',
				span: 6,
			},
		],
	},
	// 列表
	tableConfig,
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			// 	处理过期
			let date = new Date().getTime()
			let endDate = new Date(item.endTime).getTime()
			let differ = endDate - date
			if( differ>=0){
				//即将过期
				let dayNum = (differ/(1000*60*60*24)).toFixed(0)
				if(Number(dayNum)<=Number(item.configValue)){
					item.daysLeftToExpire = dayNum
				}
			}else{
				// 已过期
				item.daysLeftToExpire = (differ/(1000*60*60*24)).toFixed(0)
			}
			return {
				...item,
				buildInfo: [item.checkinBuilding, item.checkinFloor, item.checkinRoom, item.checkinBed],
				buildInfoText: [item.checkinBuilding, item.checkinFloor, item.checkinRoom, item.checkinBed].join('/'),
			}
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		if (form.fillingTimeBetween&&form.fillingTimeBetween.length > 0) {
			form.fillingTimeBetween = form.fillingTimeBetween.join(',')
		}
		return new Promise((resolve, reject) => {
			resolve(formateBuilData(form))
		})
	},
}
